/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDVisualizarChamAtr.java
 *
 * Created on 13/01/2012, 19:51:28
 */
package view.admin;

import control.ChamadoControl;
import java.awt.Frame;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import javax.swing.table.TableCellRenderer;
import model.Chamado;
import model.Pessoa;
import model.Resposta;
import model.tablemodel.RespostasTableModel;
import util.CellRenderer;

/**
 *
 * @author Felipe
 */
public class JDVisualizarChamAtr extends javax.swing.JDialog {

    private ChamadoControl control;
    private Chamado chamado;
    private RespostasTableModel tableModel;
    private Pessoa usuarioLogado;
    private SimpleDateFormat sdf1;
    private SimpleDateFormat sdf2;
    private SimpleDateFormat sdf3;    
    
    public JDVisualizarChamAtr(Frame parent, boolean modal, boolean encerrado, Chamado chamado,
                               Pessoa usuarioLogado) {
        super(parent, modal);
        inicializarSdfs();
        control = ChamadoControl.getControl();
        this.chamado = chamado;
        this.usuarioLogado = usuarioLogado;
        tableModel = new RespostasTableModel(chamado.getRespostas());
        initComponents();
        selecionarAba(0);
        preencherCamposGeral();     
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        pnlGeral = new javax.swing.JPanel();
        pnlGeralCentro = new javax.swing.JPanel();
        lblId = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        lblSolicitante = new javax.swing.JLabel();
        txtSolicitante = new javax.swing.JTextField();
        lblDtAbertura = new javax.swing.JLabel();
        ftxtDtAbertura = new javax.swing.JFormattedTextField();
        ftxtHrAbertura = new javax.swing.JFormattedTextField();
        lblDtEncerrado = new javax.swing.JLabel();
        ftxtDtEncerrado = new javax.swing.JFormattedTextField();
        ftxtHrEncerrado = new javax.swing.JFormattedTextField();
        lblResponsavel = new javax.swing.JLabel();
        txtResponsavel = new javax.swing.JTextField();
        lblTecnicoAtribuido = new javax.swing.JLabel();
        txtTecnico = new javax.swing.JTextField();
        txtAssunto = new javax.swing.JTextField();
        lblAssunto = new javax.swing.JLabel();
        lblMensagem = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txaMensagem = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblRespostas = new javax.swing.JTable();
        pnlGeralBtn = new javax.swing.JPanel();
        btnFechar = new javax.swing.JButton();
        pnlDetalhes = new javax.swing.JPanel();
        pnlInterCentro = new javax.swing.JPanel();
        lblDtInicioDetalhes = new javax.swing.JLabel();
        lblDtTerminoDetalhes = new javax.swing.JLabel();
        ftxtDtInicioDetalhes = new javax.swing.JFormattedTextField();
        ftxtHrInicioDetalhes = new javax.swing.JFormattedTextField();
        ftxtDtTerminoDetalhes = new javax.swing.JFormattedTextField();
        ftxtHrTerminoDetalhes = new javax.swing.JFormattedTextField();
        lblPessoaDetalhes = new javax.swing.JLabel();
        lblDescricaoDetalhes = new javax.swing.JLabel();
        txtRespondenteDetalhes = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        txaDescricaoDetalhes = new javax.swing.JTextArea();
        pnlInterBtn = new javax.swing.JPanel();
        btnVoltarDetalhes = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Visualizar chamado");

        pnlGeral.setLayout(new java.awt.BorderLayout());

        pnlGeralCentro.setPreferredSize(new java.awt.Dimension(300, 576));

        lblId.setText("Id");

        txtId.setEditable(false);

        lblSolicitante.setText("Solicitante");

        txtSolicitante.setEditable(false);

        lblDtAbertura.setText("Aberto em");

        ftxtDtAbertura.setEditable(false);

        ftxtHrAbertura.setEditable(false);

        lblDtEncerrado.setText("Encerrado em");

        ftxtDtEncerrado.setEditable(false);

        ftxtHrEncerrado.setEditable(false);

        lblResponsavel.setText("Responsável");

        txtResponsavel.setEditable(false);

        lblTecnicoAtribuido.setText("Técnico");

        txtTecnico.setEditable(false);

        txtAssunto.setEditable(false);

        lblAssunto.setText("Assunto");

        lblMensagem.setText("Mensagem");

        txaMensagem.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
        txaMensagem.setColumns(20);
        txaMensagem.setLineWrap(true);
        txaMensagem.setRows(5);
        txaMensagem.setWrapStyleWord(true);
        jScrollPane2.setViewportView(txaMensagem);

        tblRespostas.setModel(tableModel);
        tblRespostas.setRowHeight(20);
        ajustarTamanhoColunas();
        tblRespostas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblRespostasMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblRespostas);

        javax.swing.GroupLayout pnlGeralCentroLayout = new javax.swing.GroupLayout(pnlGeralCentro);
        pnlGeralCentro.setLayout(pnlGeralCentroLayout);
        pnlGeralCentroLayout.setHorizontalGroup(
            pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlGeralCentroLayout.createSequentialGroup()
                        .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblAssunto)
                            .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(lblDtAbertura)
                                        .addComponent(lblId)
                                        .addComponent(lblMensagem)))
                                .addComponent(lblResponsavel)))
                        .addGap(18, 18, 18)
                        .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtAssunto, javax.swing.GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
                            .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                                .addComponent(txtResponsavel, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(lblTecnicoAtribuido)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTecnico, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE))
                            .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                                .addComponent(ftxtDtAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ftxtHrAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblDtEncerrado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ftxtDtEncerrado, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ftxtHrEncerrado, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                            .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                                .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblSolicitante)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtSolicitante, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE))))
                .addGap(58, 58, 58))
        );
        pnlGeralCentroLayout.setVerticalGroup(
            pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlGeralCentroLayout.createSequentialGroup()
                        .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblSolicitante)
                            .addComponent(txtSolicitante, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ftxtDtAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ftxtHrAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblDtEncerrado)
                            .addComponent(lblDtAbertura)
                            .addComponent(ftxtDtEncerrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ftxtHrEncerrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(lblId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtTecnico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblTecnicoAtribuido))
                        .addComponent(lblResponsavel))
                    .addComponent(txtResponsavel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAssunto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAssunto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlGeralCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMensagem)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(106, 106, 106))
        );

        pnlGeral.add(pnlGeralCentro, java.awt.BorderLayout.CENTER);

        pnlGeralBtn.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlGeralBtn.setPreferredSize(new java.awt.Dimension(50, 60));

        btnFechar.setText("Fechar");
        btnFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFecharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlGeralBtnLayout = new javax.swing.GroupLayout(pnlGeralBtn);
        pnlGeralBtn.setLayout(pnlGeralBtnLayout);
        pnlGeralBtnLayout.setHorizontalGroup(
            pnlGeralBtnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlGeralBtnLayout.createSequentialGroup()
                .addContainerGap(486, Short.MAX_VALUE)
                .addComponent(btnFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );
        pnlGeralBtnLayout.setVerticalGroup(
            pnlGeralBtnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlGeralBtnLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnFechar)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pnlGeral.add(pnlGeralBtn, java.awt.BorderLayout.PAGE_END);

        jTabbedPane1.addTab("Geral", pnlGeral);

        pnlDetalhes.setLayout(new java.awt.BorderLayout());

        lblDtInicioDetalhes.setText("Data de inicio");

        lblDtTerminoDetalhes.setText("Data de término");

        ftxtDtInicioDetalhes.setEditable(false);

        ftxtHrInicioDetalhes.setEditable(false);

        ftxtDtTerminoDetalhes.setEditable(false);

        ftxtHrTerminoDetalhes.setEditable(false);

        lblPessoaDetalhes.setText("Respondente");

        lblDescricaoDetalhes.setText("Descrição");

        txtRespondenteDetalhes.setEditable(false);

        txaDescricaoDetalhes.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
        txaDescricaoDetalhes.setColumns(20);
        txaDescricaoDetalhes.setLineWrap(true);
        txaDescricaoDetalhes.setRows(5);
        jScrollPane3.setViewportView(txaDescricaoDetalhes);

        javax.swing.GroupLayout pnlInterCentroLayout = new javax.swing.GroupLayout(pnlInterCentro);
        pnlInterCentro.setLayout(pnlInterCentroLayout);
        pnlInterCentroLayout.setHorizontalGroup(
            pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInterCentroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlInterCentroLayout.createSequentialGroup()
                        .addComponent(lblDtInicioDetalhes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ftxtDtInicioDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ftxtHrInicioDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDtTerminoDetalhes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ftxtDtTerminoDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ftxtHrTerminoDetalhes))
                    .addGroup(pnlInterCentroLayout.createSequentialGroup()
                        .addGroup(pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblDescricaoDetalhes)
                            .addComponent(lblPessoaDetalhes))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtRespondenteDetalhes)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE))))
                .addGap(68, 68, 68))
        );
        pnlInterCentroLayout.setVerticalGroup(
            pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInterCentroLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDtInicioDetalhes)
                    .addComponent(ftxtDtInicioDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftxtHrInicioDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDtTerminoDetalhes)
                    .addComponent(ftxtDtTerminoDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftxtHrTerminoDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPessoaDetalhes)
                    .addComponent(txtRespondenteDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(pnlInterCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDescricaoDetalhes)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(90, Short.MAX_VALUE))
        );

        pnlDetalhes.add(pnlInterCentro, java.awt.BorderLayout.CENTER);

        pnlInterBtn.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlInterBtn.setPreferredSize(new java.awt.Dimension(50, 60));

        btnVoltarDetalhes.setText("Voltar");
        btnVoltarDetalhes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarDetalhesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlInterBtnLayout = new javax.swing.GroupLayout(pnlInterBtn);
        pnlInterBtn.setLayout(pnlInterBtnLayout);
        pnlInterBtnLayout.setHorizontalGroup(
            pnlInterBtnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInterBtnLayout.createSequentialGroup()
                .addContainerGap(500, Short.MAX_VALUE)
                .addComponent(btnVoltarDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlInterBtnLayout.setVerticalGroup(
            pnlInterBtnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInterBtnLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnVoltarDetalhes)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pnlDetalhes.add(pnlInterBtn, java.awt.BorderLayout.PAGE_END);

        jTabbedPane1.addTab("Detalhes", pnlDetalhes);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-661)/2, (screenSize.height-558)/2, 661, 558);
    }// </editor-fold>//GEN-END:initComponents

    private void btnVoltarDetalhesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarDetalhesActionPerformed
        selecionarAba(0);     
	}//GEN-LAST:event_btnVoltarDetalhesActionPerformed

	private void tblRespostasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblRespostasMouseClicked
		if (evt.getClickCount() == 2) {             
                    preencherCamposDetalhes();                             
		}     
	}//GEN-LAST:event_tblRespostasMouseClicked

    private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnFecharActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnFechar;
    private javax.swing.JButton btnVoltarDetalhes;
    private javax.swing.JFormattedTextField ftxtDtAbertura;
    private javax.swing.JFormattedTextField ftxtDtEncerrado;
    private javax.swing.JFormattedTextField ftxtDtInicioDetalhes;
    private javax.swing.JFormattedTextField ftxtDtTerminoDetalhes;
    private javax.swing.JFormattedTextField ftxtHrAbertura;
    private javax.swing.JFormattedTextField ftxtHrEncerrado;
    private javax.swing.JFormattedTextField ftxtHrInicioDetalhes;
    private javax.swing.JFormattedTextField ftxtHrTerminoDetalhes;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblAssunto;
    private javax.swing.JLabel lblDescricaoDetalhes;
    private javax.swing.JLabel lblDtAbertura;
    private javax.swing.JLabel lblDtEncerrado;
    private javax.swing.JLabel lblDtInicioDetalhes;
    private javax.swing.JLabel lblDtTerminoDetalhes;
    private javax.swing.JLabel lblId;
    private javax.swing.JLabel lblMensagem;
    private javax.swing.JLabel lblPessoaDetalhes;
    private javax.swing.JLabel lblResponsavel;
    private javax.swing.JLabel lblSolicitante;
    private javax.swing.JLabel lblTecnicoAtribuido;
    private javax.swing.JPanel pnlDetalhes;
    private javax.swing.JPanel pnlGeral;
    private javax.swing.JPanel pnlGeralBtn;
    private javax.swing.JPanel pnlGeralCentro;
    private javax.swing.JPanel pnlInterBtn;
    private javax.swing.JPanel pnlInterCentro;
    private javax.swing.JTable tblRespostas;
    private javax.swing.JTextArea txaDescricaoDetalhes;
    private javax.swing.JTextArea txaMensagem;
    private javax.swing.JTextField txtAssunto;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtRespondenteDetalhes;
    private javax.swing.JTextField txtResponsavel;
    private javax.swing.JTextField txtSolicitante;
    private javax.swing.JTextField txtTecnico;
    // End of variables declaration//GEN-END:variables

    private void preencherCamposDetalhes() {
        Resposta resposta = tableModel.getRespostaEJB(getLinha());
        
        if (resposta.isAgindo()) {
            JOptionPane.showMessageDialog(null, "Esta intervenção não foi concluída. \n" +
                                            "Aguarde sua conclusão e tente novamente");
        } else {
            ftxtDtInicioDetalhes.setText(sdf1.format(resposta.getInicio().getTime()));
            ftxtHrInicioDetalhes.setText(sdf2.format(resposta.getInicio().getTime()));
            ftxtDtTerminoDetalhes.setText(sdf1.format(resposta.getTermino().getTime()));
            ftxtHrTerminoDetalhes.setText(sdf2.format(resposta.getTermino().getTime()));
            txtRespondenteDetalhes.setText(resposta.getRespondente().getNome());
            txaDescricaoDetalhes.setText(resposta.getDescricao());
            selecionarAba(1);
        }
    }
    
    private void preencherCamposGeral() {        
        txtId.setText(String.valueOf(chamado.getId()));
        txtSolicitante.setText(chamado.getSolicitante().getNome());
        ftxtDtAbertura.setText(sdf1.format(chamado.getDtAbertura().getTime()));
        ftxtHrAbertura.setText(sdf2.format(chamado.getDtAbertura().getTime()));
        
        if (chamado.getDtEncerramento() != null) {
            ftxtDtEncerrado.setText(sdf1.format(chamado.getDtEncerramento().getTime()));
            ftxtHrEncerrado.setText(sdf2.format(chamado.getDtEncerramento().getTime()));
        } else {
            ftxtDtEncerrado.setText(null);
            ftxtHrEncerrado.setText(null);
        }
        txtResponsavel.setText(chamado.getResponsavel().getNome());
        
        if (chamado.getUltimoAtribuido() == null) {
            txtTecnico.setText("Chamado finalizado sem atribuição");
        } else {
            txtTecnico.setText(chamado.getUltimoAtribuido().getNome());
        }
        
        txtAssunto.setText(chamado.getTitulo());
        txaMensagem.setText(chamado.getDescricao());
    }
   
    private void ajustarTamanhoColunas() {
        // Centralizar conteudo da células
        TableCellRenderer tcr = new CellRenderer();  
        
        tblRespostas.getColumnModel().getColumn(0).setCellRenderer(tcr);
        tblRespostas.getColumnModel().getColumn(1).setCellRenderer(tcr);
        
        tblRespostas.getColumnModel().getColumn(0).setMinWidth(120);
        tblRespostas.getColumnModel().getColumn(0).setMaxWidth(130);
        tblRespostas.getColumnModel().getColumn(1).setMinWidth(120);
        tblRespostas.getColumnModel().getColumn(1).setMaxWidth(130);
        tblRespostas.getColumnModel().getColumn(2).setMinWidth(100);
        tblRespostas.getColumnModel().getColumn(2).setMaxWidth(150);
        tblRespostas.getColumnModel().getColumn(3).setMinWidth(100);     
    }

    private int getLinha() {
        return tblRespostas.convertRowIndexToModel(tblRespostas.getSelectedRow());
    }
    
    private void limparCamposDetalhes() {
        ftxtDtInicioDetalhes.setText("");
        ftxtHrInicioDetalhes.setText("");
        ftxtDtTerminoDetalhes.setText("");
        ftxtHrTerminoDetalhes.setText("");
        txtRespondenteDetalhes.setText("");
        txaDescricaoDetalhes.setText("");
    }
    
    private void selecionarAba(int aba) {
        switch (aba) {
            case 0 :    
                        jTabbedPane1.setSelectedIndex(0);
                        jTabbedPane1.setEnabledAt(0, true);
                        jTabbedPane1.setEnabledAt(1, false);                           
                        break;
                
            case 1 :    jTabbedPane1.setSelectedIndex(1); 
                        jTabbedPane1.setEnabledAt(0, false);
                        jTabbedPane1.setEnabledAt(1, true);                        
                        break;                 
        }
    }

    
    
    private void inicializarSdfs() {
        sdf1 = new SimpleDateFormat("dd/MM/yyyy");
        sdf1.setLenient(false);
        sdf2 = new SimpleDateFormat("HH:mm");
        sdf2.setLenient(false);
        sdf3 = new SimpleDateFormat("dd/MM/yyyyHH:mm");
        sdf3.setLenient(false);
    }
}
